package com.thirteenClassicsServer.mapper;

import com.thirteenClassics.dto.*;
import com.thirteenClassics.entity.AllSentence;
import com.thirteenClassics.entity.Sentence;
import com.thirteenClassics.vo.SentenceVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SentenceMapper {
    List<Sentence> selectSentence(Sentence sentence, String tableName);


    void update(Sentence sentence, String tableName);

    void insert(Sentence sentence, String tableName);

    void insertJdbSentence(Sentence sentence);

    Sentence selectByEntryIDAndOrder(SentenceSelectDYBDTO sentenceSelectDYBDTO, String tableName);

    List<Sentence> selectByEntryIDAndBanben(EntryIDAndBanbenDTO entryIDAndBanbenDTO, String tableName);

    Sentence selectOneSentence(EntryDTO entryDto, String tableName);

    Sentence selectOneSentenceJdb(MarkJdbDto markJdbDto);

    @Delete("delete from ${tableName} where sentence_id = #{sentences.sentenceId}")
    void deleteSentence(Sentence sentences, String tableName);

    @Update("update ${tableName} set order_Jdb_flag =0 where sentence_id=#{id}")
    void updateJdbFlagTo0(Long id, String tableName);

    @Update("update ${tableName} set order_Jdb_flag =1 where sentence_id=#{id}")
    void updateJdbFlagTo1(Long id, String tableName);

    Sentence selectSentenceId(SentenceSelectDYBDTO sentenceSelectDYBDTO3, String tableName);

    @Delete("delete from ${tableName} where entry_id=#{entryId}")
    void deleteSentenceByEntryId(Long entryId, String tableName);

    List<SentenceVO> selectSentenceOnlyJdb(Sentence sentence);

    @Select("select count(*) from sentence_jdb where entry_id=#{entryId} and delete_flag = 0")
    Integer selectSentenceSumOnlyJdb(Sentence sentence);

    List<Sentence> selectSentenceJdbId(SentenceSelectDYBDTO sentenceSelectDYBDTO3);


    Sentence selectByEntryIDAndOrderJdb(SentenceSelectDYBDTO sentenceSelectDYBDTO2);

    @Update("update sentence_jdb set explainS=#{explain} , fc=#{fc} ,book_operator=#{bookOperator},"
            + "book_optime=#{bookOptime} where sentence_ids=#{sentenceIds} and entry_id=#{entryId} and "
            + "paragraph_ids=#{paragraphIds}")
    void updateJdbSentece(MarkJdbDto markJdbDto);

    Sentence selectSentenceIdDZB(SentenceSelectDYBDTO sentenceSelectDYBDTO, String tableName);

    List<Sentence> selectSentenceById(List<Long> jdbId);

    @Select("select sentence_id from sentence_jdb where entry_id=#{entryIdJdb} and sentence_ids=#{sentenceIds} and "
            + "paragraph_ids=#{paragraphIds} and delete_flag = 0")
    Long selectSentenceIdJdbByEntryIdAndSentenceIdsAndParagraphIds(Long entryIdJdb, Long sentenceIds,
            Long paragraphIds);

    @Select("select explainS from sentence_jdb where entry_id=#{entryIdJdb} and sentence_ids=#{sentenceIds} and "
            + "paragraph_ids=#{paragraphIds} and delete_flag = 0")
    String selectexplainSJdbByEntryIdAndSentenceIdsAndParagraphIds(Long entryIdJdb, Long sentenceIds,
            Long paragraphIds);

    void updateCompSentece(MarkCompDto markCompDto, String getTableName);

    @Select("select sentence_ids,paragraph_ids from ${tableName} where entry_id=#{id} and banben='对照版' order by "
            + "paragraph_ids asc , sentence_ids asc")
    List<AllSentence> selectAllSentence(Long id, String tableName);

    @Select("select count(*) from ${tableName} where entry_id=#{id} and banben='对照版' order by "
            + "paragraph_ids asc , sentence_ids asc")
    Integer selectAllSentenceSum(Long id, String tableName);

    @Select("select sentence_id, entry_id, sentence_ids, paragraph_ids, sentence from sentence_jdb where entry_id=#{entryId} and delete_flag = 0;")
    List<Sentence> selectSentenceJdb(int entryId);


    @Select("select entry_id from sentence_jdb where sentence_id=#{sentenceId} and delete_flag = 0")
    Long getEntryIdBySentenceId(Long sentenceId);


    void updateSentence(Sentence sentence, String getTableName);
}
